package org.coonect;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager; //import java.sql.ResultSet;

import java.util.Properties;

//import com.mysql.jdbc.PreparedStatement;

public class ConnectionToBase {

	public static void main(String[] args) {
		if (!connect()) {
			System.out.println("Could not connect");
		} else {

		}
	}

	public static boolean connect() {

		@SuppressWarnings("unused")
		Connection con;
		// PreparedStatement pst = null;
		// ResultSet rs = null;

		Properties props = new Properties();
		FileInputStream in = null;

		try {
			in = new FileInputStream("database.properties");
			props.load(in);

		} catch (FileNotFoundException ex) {

			return false;

		} catch (IOException ex) {

			return false;

		} finally {

			try {
				if (in != null) {
					in.close();
				}
			} catch (IOException ex) {
				return false;
			}
		}

		String url = props.getProperty("db.url");
		String user = props.getProperty("db.user");
		String passwd = props.getProperty("db.passwd");

		try {

			con = DriverManager.getConnection(url, user, passwd);

		} catch (Exception ex) {
			return false;

		}

		return true;

	}

}
